package ToYesterday.Day14_getleaf_sum;

import ToYesterday.Day13_TreeNode.TNode;
import org.junit.Test;

public class GetLeafSum {
    int sum = 0;

    TNode T;

    void init(){
        T = new TNode(2);
        TNode n1 = new TNode(3);
        TNode n2 = new TNode(5);
        TNode n3 = new TNode(6);
        TNode n4 = new TNode(12);
        TNode n5 = new TNode(7);
        T.left = n1;
        T.right = n2;
        n1.left = n3;
        n1.right = n4;
        n2 .right = n5;
    }


    @Test
    public void Test(){
        init();
        getSumLeaves(T);
        System.out.println(sum);
    }

    public void getSumLeaves(TNode T){
        if (T.left==null&&T.right==null){
            sum = T.val+sum;
        }
        if (T.left!=null)getSumLeaves(T.left);
        if (T.right!=null)getSumLeaves(T.right);

    }
}
